import {message} from 'antd'
const initState = []

function cartList(prev=initState, action){
    const {type, data} = action
    let newState
    switch (type) {
        case 'add':
            let flag = false
            prev.forEach(r=>{
                if(r && (r.id===data.id)){
                    flag = true
                }
            })
            if (!flag) {
                newState = [...prev , data]
            }else{
                message.warn('请勿重复添加试题')
                newState = prev
            }
            return newState
        default:
            return prev
    }
}

export default cartList